define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/shoproomset/index' + location.search,
                    add_url: 'shop/shoproomset/add',
                    edit_url: 'shop/shoproomset/edit',
                    del_url: 'shop/shoproomset/del',
                    multi_url: 'shop/shoproomset/multi',
                    import_url: 'shop/shoproomset/import',
                    table: 'shop_room_set',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                singleSelect:true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('套餐名'), operate: false},
                        {field: 'shop_id', title: __('店铺ID')},
                        {field: 'shop.name', title: __('店铺')},
                        {
                            field: 'room.name',
                            title: __('房间号'),
                            align: 'left',
                            formatter: function (value, row, index, field) {
                                if (value == null) {
                                    return "";
                                }
                                return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='" + value + "'>" + value + "</span>";
                            },
                            cellStyle: function (value, row, index, field) {
                                return {
                                    css: {
                                        "white-space": "nowrap",
                                        "text-overflow": "ellipsis",
                                        "overflow": "hidden",
                                        "max-width": "220px"
                                    }
                                };
                            }, operate: false
                        },
                        {field: 'room_id', title: __('房间ID'), operate: false},
                        {field: 'hour', title: __('小时'), operate: false},
                        {field: 'amount', title: __('价格'), operate: false},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
